Editor.Init = {
	state: function () {
		Editor.STATE.CANVAS = Raphael("canvas", Editor.CONFIG.CANVAS_WIDTH, Editor.CONFIG.CANVAS_HEIGHT);
		Editor.STATE.DRAGGERCANVAS = new Editor.DraggerCanvas();
		Editor.STATE.DRAGGERCANVAS.draw();
		Editor.STATE.CMDSTACK = new JS.Command.Stack();
		Editor.STATE.DRAGGER = undefined;
		Editor.STATE.ADDSHAPE = undefined;
		Editor.STATE.LANG = Editor.LANG.EN;
		Editor.STATE.SHAPES = new JS.Hash();
		Editor.STATE.SELECTED = new Array();
	},
	lang: function () {
		document.title = Editor.STATE.LANG.TITLE;
		$("#logo").text(Editor.STATE.LANG.TITLE); 
		$("#buttonUndo").text(Editor.STATE.LANG.UNDO); 
		$("#buttonRedo").text(Editor.STATE.LANG.REDO); 
		$("#buttonAddResource").text(Editor.STATE.LANG.ADD_RESOURCE); 
		$("#buttonAddLiteral").text(Editor.STATE.LANG.ADD_LITERAL); 
		$("#buttonDeleteSelected").text(Editor.STATE.LANG.DELETE_SELECTED); 
		$("#buttonToggleLangUi").text(Editor.STATE.LANG.TOGGLE_LANG_UI); 
		$("#buttonRefreshPanel").text(Editor.STATE.LANG.REFRESH_PANEL); 
		$("#buttonSendAddResource").text(Editor.STATE.LANG.SEND); 
		$("#buttonCloseAddResource").text(Editor.STATE.LANG.CLOSE); 
		$("#buttonSendAddLiteral").text(Editor.STATE.LANG.SEND); 
		$("#buttonCloseAddLiteral").text(Editor.STATE.LANG.CLOSE); 
		$("#buttonSendImport").text(Editor.STATE.LANG.SEND); 
		$("#buttonCloseImport").text(Editor.STATE.LANG.CLOSE); 
		$("#buttonCloseExport").text(Editor.STATE.LANG.CLOSE); 
		$("#buttonNew").text(Editor.STATE.LANG.NEW_DIAGRAM); 
		$("#buttonExport").text(Editor.STATE.LANG.EXPORT_DIAGRAM); 
		$("#buttonImport").text(Editor.STATE.LANG.IMPORT_DIAGRAM); 
		$("#buttonOptions").text(Editor.STATE.LANG.OPTIONS); 
		$("#buttonCloseOptions").text(Editor.STATE.LANG.CLOSE); 
		$("#buttonSendOptions").text(Editor.STATE.LANG.SEND); 
		$("#buttonAbout").text(Editor.STATE.LANG.ABOUT);
		$("#titleAddResource").text(Editor.STATE.LANG.RESOURCE); 
		$("#titleAddLiteral").text(Editor.STATE.LANG.LITERAL); 
		$("#titleImport").text(Editor.STATE.LANG.IMPORT_DIAGRAM); 
		$("#titleExport").text(Editor.STATE.LANG.EXPORT_DIAGRAM); 
		$("#titleAddLiteral").text(Editor.STATE.LANG.LITERAL); 
		$("#buttonTextImportClear").text(Editor.STATE.LANG.CLEAR); 
	},
	buttons: function () {
		$('#buttonUndo').click(Editor.Util.undo);
		$('#buttonRedo').click(Editor.Util.redo);
		$('#buttonAddResource').click(Editor.Util.prepareAddResource);
		$('#buttonAddLiteral').click(Editor.Util.prepareAddLiteral);
		$('#buttonToggleLangUi').click(Editor.Util.toggleLang);
		$('#buttonSendAddLiteral').click(Editor.Util.updateLiteral);
		$('#buttonCloseAddLiteral').click(Editor.Util.cancelUpdateLiteral);
		$('#buttonSendAddResource').click(Editor.Util.updateResource);
		$('#buttonCloseAddResource').click(Editor.Util.cancelUpdateResource);
		$('#buttonDeleteSelected').click(Editor.Util.removeShapes);
		$('#buttonImport').click(Editor.File.prepareImportDiagram);
		$('#buttonSendImport').click(Editor.File.importDiagram);
		$('#buttonExport').click(Editor.File.exportDiagram);
		$('#buttonCloseExport').click(Editor.File.closeExport);
		$('#buttonCloseImport').click(Editor.File.closeImport);
		$('#buttonNew').click(Editor.File.newDiagram);
		$('#buttonOptions').click(Editor.Util.prepareOptions);
		$('#buttonSendOptions').click(Editor.Util.updateOptions);
		$('#buttonCloseOptions').click(Editor.Util.closeOptions);
		$('#buttonAbout').click(Editor.Util.about);
		$('.buttonCloseAbout').click(Editor.Util.closeAbout);
		$("#buttonTextImportClear").click(Editor.File.textImportClear);

		$('#canvasAdd').click(Editor.Util.canvasAddClick);
	},
	ui: function () {
		Editor.Init.lang();
		Editor.Init.buttons();
		Editor.Keys.bind();
		document.onmousemove = function (e) {
			e = e || window.event;
			if (Editor.Util.isDragging()) {
				Editor.STATE.DRAGGER.onmousemove(e);
			}
		}
		document.onmouseup = function () {
			if (Editor.Util.isDragging()) {
				Editor.STATE.DRAGGER.onmouseup();
			}
		}
	},
	open: function () {
		var sample = Editor.Util.gup('sample');
		if (sample) {
			var url = 'samples/' + sample + '.json';
			var arrObjects;
 			$.ajax({
				url: url,
				type: "GET",
				dataType: "json",
				cache: false,
				async: false,
				success: function(data) {
					arrObjects = data;
				}
			});
			Editor.Util.drawObjects(arrObjects);
			delete arrObjects;
		} else {
			Editor.Util.about();
		}
	},
	init: function () {
		Editor.CONFIG.CANVAS_HEIGHT = $(window).height()-$("#canvas").position().top;
		Editor.CONFIG.CANVAS_WIDTH = $(window).width()-$("#canvas").position().left;

		Editor.Init.state();
		Editor.Init.ui();
		Editor.Init.open();
       $().mousemove(function(e){
          $('#status').html( 'w: ' + $(window).width() + 'x' + $(window).height() + ' m: ' + e.pageX +', '+ e.pageY);
       }); 

	}
}
